package kr.co.bettersoftportal.site.web.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * view �������� ��û�� ���ؼ� encoding; ó���Ѵ�.
 * JBoss �Ǵ� Tomcat�� ��� Request�� encoding ��d�� f��� �����Ϸx� �Ʒ��� ���� ���� ��d����(server.xml)����
 * Connector �κ�; ��d�ؾ� �Ѵ�.
 * <p>
 * <pre>
 * Connector port="8080" address="&{jboss.bind.address}"
 *     maxThreads="250" maxHttpHeaderSize="8192"
 *     emptySessionPath="true" protocol="HTTP/1.1"
 *     enableLookups="false" redirectPort="8443" acceptCount="100"
 *     connectionTimeout="20000" disableUploadTimeout="true" useBodyEncodingForURI="true" URIEncoding="UTF8"/&gt;
 * ...............
 * </pre>
 * </p>
 *
 *
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2009. 1. 21
 * Time: ���� 2:17:00
 * To change this template use File | Settings | File Templates.
 */
public class RequestEncodingFilter implements Filter {
    private String encoding = null;

    protected FilterConfig filterConfig = null;

	public void init(FilterConfig filterConfig) throws ServletException {
		this.filterConfig = filterConfig;
		this.encoding = this.filterConfig.getInitParameter("encoding");
	}

    public void destroy() {
		this.encoding = null;
		this.filterConfig = null;
	}

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		if (encoding != null && !"".equals(encoding)) {
			request.setCharacterEncoding(encoding);
		}
		chain.doFilter(request, response);
	}
}
